package StrategyCode.ConcreteStrategy;
import StrategyCode.EncryptStrategy;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class AESEncrypt extends EncryptStrategy {

    @Override
    public String encrypt(String data) {
        try {
            KeyGenerator keyGen = KeyGenerator.getInstance("AES");
            keyGen.init(128);
            SecretKey secretKey = keyGen.generateKey();
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
            byte[] encryptedData = cipher.doFinal(data.getBytes());
            return new String(encryptedData);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
